﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.ComponentModel;
using DailyComics.Common.Model;

namespace DailyStrips.ViewModel
{

  class MainWindowViewModel : BaseViewModel
  {
    private ImageSource image;
    private MainModel model;
    private DateTime currentDate;

    public MainWindowViewModel(MainModel model)
    {
      // TODO: Complete member initialization
      this.model = model;

      currentDate = DateTime.Now;
      Image = model.GetImageByDaye(currentDate);
    }

    public string WindowHeader
    {
      get
      {
        return "Wulffmorgenthaler Today " + CurrentDate.ToString("dd/MMMM/yyyy");
      }
    }

    public DateTime CurrentDate
    {
      get
      {
        return currentDate;
      }
      set
      {
        if (value != currentDate)
        {
          currentDate = value;
          OnPropertyChanged("CurrentDate");
          OnPropertyChanged("WindowHeader");
        }
      }
    }

    public ImageSource Image
    {
      get
      {
        return image;
      }
      set
      {
        if (value != image)
        {
          image = value;
          OnPropertyChanged("Image");
        }
      }
    }

    internal void NavigateBack()
    {
      if (currentDate >= DateTime.Parse("2007-02-15"))
      {
        CurrentDate -= TimeSpan.FromDays(1);
        Image = model.GetImageByDaye(currentDate);
      }
    }

    internal void NavigateForward()
    {
      if (currentDate.DayOfYear < DateTime.Now.DayOfYear)
      {
        CurrentDate += TimeSpan.FromDays(1);
        Image = model.GetImageByDaye(currentDate);
      }

    }
  }
}
